package com.qing.servicevod.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.qing.servicebase.utils.ResponseResult;
import com.qing.servicevod.constant.ConstantPropertiesUtil;
import com.qing.servicevod.utils.AliyunVodSDKUtils;
import org.springframework.web.bind.annotation.*;

import javax.naming.spi.ResolveResult;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName Yjx
 * @Description TODO
 * @date 2022/9/17 22:56
 * @Version 1.0
 */
@CrossOrigin //跨域
@RestController
@RequestMapping("/eduvod/video")
public class VideoController {

    @GetMapping("/get-play-auth/{videoId}")
    public ResponseResult getVideoPlayAuth(@PathVariable("videoId") String videoId) throws
            Exception {
        //获取阿里云存储相关常量
        String accessKeyId = ConstantPropertiesUtil.ACCESS_KEY_ID;
        String accessKeySecret = ConstantPropertiesUtil.ACCESS_KEY_SECRET;
        //初始化
        DefaultAcsClient client = AliyunVodSDKUtils.initVodClient(accessKeyId,
                accessKeySecret);
        //请求
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId(videoId);
        //响应
        GetVideoPlayAuthResponse response = client.getAcsResponse(request);
        //得到播放凭证
        String playAuth = response.getPlayAuth();
        //返回结果
        Map<String, String> map = new HashMap<String,String>();
        return ResponseResult.ofSuccess(map);
    }


}
